const typescript = require("rollup-plugin-typescript2");
const sourceMaps = require('rollup-plugin-sourcemaps')
const commonjs = require('@rollup/plugin-commonjs')
const resolve = require('@rollup/plugin-node-resolve')
const path = require('path')

module.exports = {
  input: './src/index.ts',
  output: [
    // IIFE 格式 - 浏览器环境
    {
      format: "iife",
      file: "dist/browser/index.js",
      name: "HtmlToDocxConverter", // 包名 自动挂载到window
      globals: {
        'docx': 'docx'
      }
    },
    // ES 模块格式 - 支持 ES 模块
    {
      format: 'es',
      file: 'dist/es/index.esm.js',
      sourcemap: true
    },
    // UMD 格式 - 浏览器环境
    {
      format: 'umd',
      name: 'HtmlToDocxConverter',
      file: 'dist/umd/index.umd.js',
      globals: {
        'docx': 'docx'
      }
    }
  ],
  // 标记这些为外部依赖
  external: ['docx'],
  plugins: [
    typescript({
      useTsconfigDeclarationDir: true, // 使用tsconfig的ts输出路径
    }),
    commonjs({ extensions: ['.js', '.ts'] }),
    resolve(),
    sourceMaps(),
  ],
}
